package com.trek;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.trek.vo.ConfigProperties;

public class MapperGenerater {
	
	
	public static void main(String[] args) {
		generateCode();
	}
	
	public static void generateCode() {
		String tables = ConfigProperties.tables;
		
		String[] args = null;
		
		if(tables.contains(",")) {
			args = tables.split(",");
		}else {
			args = new String[] {tables};
		}
		
		generateByTables(false, "", args);
	}

	private static void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) {
		
		
		GlobalConfig config = new GlobalConfig();
		config.setEnableCache(false);
		config.setBaseResultMap(true);// XML ResultMap
		config.setBaseColumnList(true);// XML columList
		
		
		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfig.setDbType(DbType.MYSQL).setUrl(ConfigProperties.url).setUsername(ConfigProperties.username).setPassword(ConfigProperties.password)
				.setDriverName(ConfigProperties.driverClass);
		
		
		StrategyConfig strategyConfig = new StrategyConfig();
		strategyConfig.setCapitalMode(true).setEntityLombokModel(false).setDbColumnUnderline(true)
				.setNaming(NamingStrategy.underline_to_camel).setInclude(tableNames);// 修改替换成你需要的表名，多个表名传数组
		
		
		config.setActiveRecord(false).setAuthor(ConfigProperties.author).setOutputDir(ConfigProperties.output).setFileOverride(true);
		
		new AutoGenerator().setGlobalConfig(config).setDataSource(dataSourceConfig).setStrategy(strategyConfig)
				.execute();
	}

}
